package impl.defaultImpl;

import design.Output;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @ClassName DefaultOutput .java
 * @Description empty
 * @Author LiuJinyu
 * @Date 2023/4/3 9:45
 * @Version 1.0
 */

public class DefaultOutput extends Output {
    private static DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
    @Override
    public void output(String calendarBuilderData) {
        String filePath = System.getProperty("user.dir")+File.separator+ LocalDateTime.now().format(df)+".ics";
        File icsFile = new File(filePath);
        try(FileOutputStream outputStream = new FileOutputStream(icsFile)){
            outputStream.write(calendarBuilderData.getBytes(StandardCharsets.UTF_8));
            outputStream.flush();
        }catch (IOException e) {
            e.printStackTrace();
        }
    }
}
